;(function(){
	$('a.panel-collapse').click(function() {
    $(this).children().toggleClass("fa-chevron-down fa-chevron-up");
    $(this).closest(".panel-heading").next().slideToggle({duration: 200});
    $(this).closest(".panel-heading").toggleClass('rounded-bottom');
    return false;
	});
	$( ".alarm" ).timeDropper({format:"HH:mm"});
    $(".saveset").click(function(){
       	var data_step=$(this).attr("data-step");
        var order_start_time=$("#order_start_time_"+data_step).val();
        var order_end_time=$("#order_end_time_"+data_step).val();
        var class_start_time=$("#class_start_time_"+data_step).val();
        var class_end_time=$("#class_end_time_"+data_step).val();
        if(data_step>1){
        	$temp=$("#class_end_time_"+(data_step-1)).val();
        	$temp1=$("#order_start_time_"+data_step).val();
        	if($temp1<$temp){
        		toastr['error']("第"+data_step+"场 的预约开始必须大于第"+(data_step-1)+"场的上课结束");
        		return false;
        	}
        }
       	if(order_start_time>order_end_time){
       		toastr['error']("请填写预约开始时间不能大于预约结束时间");
       		return;
       	}
       	if(order_end_time>class_start_time){
       		toastr['error']("请填写预约结束时间不能大于上课开始时间");
       		return;
       	}
       	if(class_start_time>class_end_time){
       		toastr['error']("请填写上课开始时间不能大于上课结束时间");
       		return;
       	}
       	
       	if($("#pcount_"+data_step)<1){
       		toastr['error']("预约人数不能小于1");
       		return;
       	}
       	loading();
       	$.post(
       		"/admin/BikeOrder/set_post",
       		{"step":data_step,
       		 "order_start_time":order_start_time,
       		 "order_end_time":order_end_time,
       		 "class_start_time":class_start_time,
       		 "class_end_time":class_end_time,
       		 "pcount":$("#pcount_"+data_step).val(),
       		},
       		function(){
       			close_loading();
       			toastr["success"]("成功");
       		}
       	);
    });
    
    $(".clearset").click(function(){
       	var data_step=$(this).attr("data-step");
        $("#order_start_time_"+data_step).val("00:00");
        $("#order_end_time_"+data_step).val("00:00");
        $("#class_start_time_"+data_step).val("00:00");
        $("#class_end_time_"+data_step).val("00:00");
       	$("#pcount_"+data_step).val("1");
       	loading();
       	$.post(
       		"/admin/BikeOrder/clear_set",
       		{
       			"step":data_step,
       		},
       		function(){
       			close_loading();
       			toastr["success"]("成功");
       		}
       	);
    
    });
    
    $(".deviceset").click(function(){
    	$step=$(this).attr("data-step");
    	$device_code=$("#device_code_"+$step).val();
    	if($device_code<1){
    		toastr["error"]("设备地址编号必须大于1");
    		return;
    	}
    	$device_no=$("#device_no_"+$step).val();
    	$device_name=$("#device_name_"+$step).val();
    	loading();
       	$.post(
       		"/admin/BikeOrder/device_set",
       		{
       			"device_code":$device_code,
       			"device_name":$device_name,
       			"device_no":$device_no
       		},
       		function(){
       			close_loading();
       			toastr["success"]("成功");
       		}
       	);
    });
    
    $(".cleardevice").click(function(){
    	$step=$(this).attr("data-step");
    	$("#device_code_"+$step).val("0");
    	$("#device_no_"+$step).val($step);
    	$("#device_name_"+$step).val("");
    	loading();
       	$.post(
       		"/admin/BikeOrder/clear_device",
       		{
       			"device_code":$device_code,
       		},
       		function(){
       			close_loading();
       			toastr["success"]("成功");
       		}
       	);
    })
})()

